package com.zzzzzz.account.signin;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.zzzzzz.account.user.UserBase;

public class CurrentUserInterceptor extends HandlerInterceptorAdapter {

	@Resource
	private OnlineService onlineService;
	
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
    	if(onlineService.isSignedIn()){
    		try {
    			UserBase userBase = onlineService.findUserBase();
    	        request.setAttribute("currentUser", userBase);
    		} catch (NoSuchOnlineUserException e) {
    			request.setAttribute("currentUser", null);
//    			e.printStackTrace();
    		}
    	}
    }

}
